package com.hengtian.roastwall.controller;

import com.hengtian.roastwall.service.impl.MomentServiceImpl;
import com.hengtian.roastwall.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/file")
@Api("文件上传接口")
public class FileController {
    @Autowired
    private MomentServiceImpl momentService;

    //可用于文章发布以及用户头像上传
    @ApiOperation("用户上传文件")
    @PostMapping("/upload")
    public ResponseResult avatarUpload(@RequestParam("file") MultipartFile file) {
        try {
            String path = momentService.imagesUpload(file);
            return new ResponseResult(200, "文件上传成功",path);
        } catch (Exception e) {
            throw new RuntimeException("文件上传失败");
        }
    }
}
